﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.AP.Enums;
using UFIDA.U9.CBO.FI.Enums;
using UFIDA.U9.CBO.SCM.Item;
using UFIDA.U9.cust.qjJSDBE;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;

namespace UFIDA.U9.CusDev.QJKJPlugInBE
{
    class ProcessForJSDInsert : IEventSubscriber
    {
        public void Notify(params object[] args)
        {

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent)) return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null || key.GetEntity() == null) return;
            //结算单
            UFIDA.U9.cust.qjJSDBE.JSDEntity jsd = key.GetEntity() as UFIDA.U9.cust.qjJSDBE.JSDEntity;
            if (jsd == null) return;

            #region 结算单新增时 判断应收单状态,会写是否联动
            //引入应收单
            AR.ARBill.ARBillHead ar = AR.ARBill.ARBillHead.Finder.FindByID(jsd.AR.ID);
            if (ar == null) return;
            //判断应收单是否为开立
            //using (ISession session = Session.Open()) {

                if (ar.DocStatus == BillStatusEnum.Opened)
                {
                    jsd.ARLinkAge = JSDLinkAge.Yes;
                    jsd.DocState = JSState.Opened;


                }
                else
                {
                    jsd.ARLinkAge = JSDLinkAge.No;
                    jsd.DocState = JSState.Opened;
                }
              //  session.Commit();
           // }
          


            #endregion

        }

    }
}
